package com.ruoyi.web.pojo.vo.insect;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.web.domain.warning.WarningInsect;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class InsectTopVO {

    @ApiModelProperty(value = "昆虫姓名")
    private String insectName;

    @ApiModelProperty(value = "昆虫数量")
    private Integer insectNum;

    @ApiModelProperty(value = "昆虫类型 1 一类害虫 2 二类害虫 3 其他 全部不传")
    private Integer insectType;

    public InsectTopVO(String insectName, Integer insectNum) {
        this.insectName = insectName;
        this.insectNum = insectNum;
    }

    public static List<InsectTopVO> getList(Map<String ,Integer> map,Map<String, WarningInsect> insectMap){
        if(CollUtil.isEmpty(map)){
            return new ArrayList<>();
        }

        return map.keySet().stream()
                .filter(key -> {
                    if(insectMap.get(key) == null){
                        System.err.println("无该昆虫: " + key);
                    }
                    return insectMap.get(key) != null;
                })
                .map(key ->{
                    InsectTopVO vo = new InsectTopVO(key, map.get(key));
                    vo.setInsectType(insectMap.get(key).getInsectType());
                    return vo;
                })
                .sorted(Comparator.comparing(InsectTopVO::getInsectNum).reversed())
                .collect(Collectors.toList());
    }

}
